import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class Upload {
	public static void upload()throws Exception{
		Connection c = mysqlConnection.connect();
		Scanner in = new Scanner(System.in);
		ResultSet cID = null;
		int categoryID = 0;
		String [] validConditions = {"Excellent", "excellent","Good", "Fair", "Poor"};
		String [] validLocations = {"US", "United States", "Canada", "Mexico"};
		String [] validCategories = {"Art", "Antique", "Automobile", "Book", "Collectible", "Electronic","General", "Random"
				, "Jewelry", "Memorabilia"};
		System.out.println("\nEnter an image of your item");
		String itemImagePath = in.nextLine();
		System.out.println("\nWhat's the condition of your item?");
		System.out.println("Excellent, Good, Fair, Poor");
		String condition = in.nextLine();
		while(!Arrays.asList(validConditions).contains(condition)){
			System.out.println("\nEnter a valid conditon");
			condition = in.nextLine();
		}
		System.out.println("\nGive a Description of your item");
		String description = in.nextLine();
		System.out.println("\nEnter valid Trade Locations");
		String location = in.nextLine();
		while(!Arrays.asList(validLocations).contains(location)){
			System.out.println("\nEnter a valid location");
			location = in.nextLine();
		}
		System.out.println("\nCategory:");
		String category = in.nextLine();
		while(!Arrays.asList(validCategories).contains(category)){
			System.out.println("\nEnter a valid category");
			category = in.nextLine();
		}
		PreparedStatement s = c.prepareStatement("SELECT CategoryID FROM Categories " +
				"WHERE Name = ?");
		s.setString(1, category);
		cID = s.executeQuery();
		while(cID.next()){
			categoryID = cID.getInt(1);
		}
		PreparedStatement p = c.prepareStatement("INSERT INTO TradeItem " +
				"(ItemCondition, ImagePath, Description, TradeLocation, CategoryID, OwnerID) VALUES (?, ?, ?, ?, ?, ?)");
		p.setString(1, condition);
		p.setString(2, itemImagePath);
		p.setString(3, description);
		p.setString(4, location);
		p.setInt(5, categoryID);
		p.setInt(6, UserLogin.userID);
		p.executeUpdate();
		System.out.println("\nItem Uploaded!");
	}
	public static void main(String[]args) throws Exception{
		upload();
	}

}
